package com.ruoyi.yl.controller;

import com.ruoyi.yl.common.Result;
import com.ruoyi.yl.domain.YlStockArrange;
import com.ruoyi.yl.domain.YlStockArrangeDrug;
import com.ruoyi.yl.domain.YlUpdateStock;
import com.ruoyi.yl.service.StockArrangeManageService;
import org.springframework.web.bind.annotation.*;
import static com.ruoyi.yl.constant.YlConstant.*;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: linKe
 * @Date: 2022/2/17 17:24
 * @FileName: StockArrangeManageController
 * @version: 1.0
 * @Description: 库存盘点
 */
@RestController
@RequestMapping("/stockArrangeManage")
public class StockArrangeManageController {
    @Resource
    private StockArrangeManageService stockArrangeManageServiceImpl;

    /**
     * 查询所有盘点信息
     *
     * @return
     */
    @GetMapping("/getAll")
    public Result<List<YlStockArrange>> getAll() {
        List<YlStockArrange> all = stockArrangeManageServiceImpl.getAll();
        return new Result<>(OP_SUCCESS_CODE, OP_SUCCESS_MSG, all);
    }


    /**
     * 根据id查药品和盘点
     */
    @GetMapping("/getOneById/{id}")
    public Result<YlStockArrangeDrug> getOneById(@PathVariable("id") Long id) {
        YlStockArrangeDrug stockArrangeDrug = stockArrangeManageServiceImpl.getOneById(id);
        return new Result<>(OP_SUCCESS_CODE, OP_SUCCESS_MSG, stockArrangeDrug);
    }

    /**
     * 新增盘点
     *
     * @return
     */
    @PostMapping("/addStockArrange")
    public int addStockArrange(YlStockArrange stockArrange) {
        long currentTimeMillis = System.currentTimeMillis();
        String second = "pd" + currentTimeMillis;
        YlStockArrange stockArrange1 = (YlStockArrange)new YlStockArrange()
                .setCheckSheetStatus(0)
                .setEmployee(5L)
                .setNumber(second)
                .setCreateTime(LocalDateTime.now());
        return stockArrangeManageServiceImpl.addStockArrange(stockArrange1);
    }

    /**
     * 根据药品的id修改库存
     *
     * @param updateStockBean
     */
    @PutMapping("/updateDrugStock")
    public void updateDrugStock(YlUpdateStock updateStockBean) {
        List<Long> ids = new ArrayList<Long>();
        ids.add(1L);
        ids.add(2L);
        List<Integer> stocks = new ArrayList<>();
        stocks.add(20);
        stocks.add(233);
        stockArrangeManageServiceImpl.updateDrugStock(new YlUpdateStock().setIds(ids).setStocks(stocks));
    }

    /**
     * 根据盘点id删数据
     */
    @DeleteMapping("/deleteStockArrange")
    public Result<String> deleteStockArrange(Long id) {
        stockArrangeManageServiceImpl.deleteStockArrange(id);
        return new Result<>(OP_SUCCESS_CODE, OP_SUCCESS_MSG, "删除成功");
    }

    /**
     * 根据盘点单号模糊查信息
     */
    @GetMapping("/getStockArrangesByNumber")
    public Result<List<YlStockArrange>> getStockArrangesByNumber(String number) {
        List<YlStockArrange> list = stockArrangeManageServiceImpl.getStockArragesByNumber(number);
        return new Result<>(OP_SUCCESS_CODE, OP_SUCCESS_MSG, list);
    }

    /**
     * 根据时间段查信息
     */
    @GetMapping("/getByCreateTime/{begin}/{end}")
    public Result<List<YlStockArrange>> getByCreateTime(@PathVariable("begin") String date1,
                                                           @PathVariable("end") String date2) {

        List<YlStockArrange> list = stockArrangeManageServiceImpl.getByCreateTime(date1, date2);
        return new Result<>(OP_SUCCESS_CODE, OP_SUCCESS_MSG, list);
    }
}
